﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2013-08-04 19:15
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BassDrop.Core.Common.Utilities
{
	/// <summary>
	/// Class providing random generation functions
	/// </summary>
	public static class RandomUtils
	{
		/// <summary>
		/// Random generator used
		/// </summary>
		private static readonly Random s_Random = new Random( (int) DateTime.UtcNow.Ticks );

		/// <summary>
		/// Generate a random string of a specified size
		/// </summary>
		/// <param name="size">the length of the resulting string</param>
		/// <returns>a random string</returns>
		/// <remarks>
		/// From http://stackoverflow.com/questions/1122483/c-sharp-random-string-generator
		/// </remarks>
		public static string RandomString( int size )
		{
			const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";

			StringBuilder builder = new StringBuilder();
			char ch;

			for ( int i = 0; i < size; i++ )
			{
				ch = chars[Convert.ToInt32( Math.Floor( chars.Length * s_Random.NextDouble() ) )];
				builder.Append( ch );
			}

			return builder.ToString();
		}
	}
}
